package com.huangyuan3h.test;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pwc.XMLConversion.Soap.Client;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	Client client =null;
	
	static String URLFusion = "https://strl069163.mso.net:10604/finGlDesktopEntry/JournalImportService?wsdl";

	static String URLWorkDay = "https://wd2-impl-services1.workday.com/ccx/service/pwc_dpt1/Staffing/v25.0?wsdl";


	
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		
		
		
		return "home";
	}
	
	
	@RequestMapping(value = "/rest/operationMap", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody HashMap<String, String> initial(String url) {
		
		client = new Client();
		
		client.InitialProject(url);

		HashMap<String, String> map = (HashMap<String, String>) client
				.GetOperationMap();
		return map;
	}
	
	
	@RequestMapping(value = "/rest/sendSoapSecurity", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody HashMap<String, String> sendSoapSecurity(String data,String operationName,String requestName,String userName,String password,String passwordType  ) {
		
		String Response="";
		
		HashMap<String, String> resultHashMap=new HashMap<String, String>();
		
		try {
			client.GenerateWSDLRequest(operationName, requestName, data);
			
			client.SetSecurity(userName, password, passwordType);
			
			Response = client.DoSubmit();
			
			System.out.println(Response);			
			
			resultHashMap.put("Response", Response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
		return resultHashMap;
	}
	
	

	@RequestMapping(value = "/rest/sendSoap", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody HashMap<String, String> sendSoap(String data,String operationName,String requestName ) {
		
		String Response="";
		
		HashMap<String, String> resultHashMap=new HashMap<String, String>();
		
		try {
			client.GenerateWSDLRequest(operationName, requestName, data);
			
			
			Response = client.DoSubmit();
			
			System.out.println(Response);			
			
			resultHashMap.put("Response", Response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
		return resultHashMap;
	}
	
	
	
	
	
	
	
}
